<link href="/theme/Admin/css/control/index.css" rel="stylesheet">
<script src="/theme/Default/js/jquery.validate.js"></script>

<form action="/admin/Users/editadmin/<?php echo $id ?>" method="post" id="userAdd">
	<input type="hidden" name="id" value="<?php echo $id ?>" id="userId"/>
	<div id="admin-control">
		<div class="admin_control_header">
			Thông tin đăng ký<span class="admin_control_notice">(Vui lòng điền đầy đủ thông tin)</span>
		</div>
		
		<?php echo $this->Session->flash();?>
		
		<div class="admin_control_row">
			<div class="admin_control_label">
				Tên thành viên :
			</div>
			<div class="admin_control_element">
				<div class="element-main">
					<input class="form-control" name="data[username]" type="text" 
					value="<?php echo $data['User']['username'] ?>" id="data_username" maxlength="60"/>
				</div>
				<div class="category_group_warntip hide">
					<div class="warntip_triangle">&nbsp;</div>
					<div class="warntip_content">
						<span>Hãy nhập tên đăng nhập</span>
			    	</div>
				</div>
			</div>
		</div>
		<div class="admin_control_row">
			<div class="admin_control_label">
				Email :
			</div>
			<div class="admin_control_element">
				<div class="element-main">
					<input class="form-control" name="data[email]" type="text" 
					value="<?php echo $data['User']['email'] ?>" id="data_email" maxlength="60"/>
				</div>
				<div class="category_group_warntip hide">
					<div class="warntip_triangle">&nbsp;</div>
					<div class="warntip_content">
						<span>Hãy nhập Email</span>
			    	</div>
				</div>
			</div>
		</div>

		<div class="admin_control_row">
			<div class="admin_control_label">
				
			</div>
			<div class="admin_control_element">
				<div class="element-main">
					<button type="submit" class="btn btn-danger" id="btn_register">Sửa thông tin</button>
				</div>
			</div>
		</div>
	</div>
</form>
<style>
	.message {
		color: blue;
		background-color: #f3f4f5;
		padding: 8px 35px 8px 14px;
		margin: 10px;
		text-shadow: 0 1px 0 rgba(255,255,255,0.5);
		border: 1px solid #fbeed5;
		-webkit-border-radius: 4px;
		-moz-border-radius: 4px;
		border-radius: 4px;
		}
</style>

<script>
	$(document).ready(function() {
    validateForm($("#userAdd"));
    initRules();
    
});
/**
 *validate 
 */
function validateForm($form){
	$form.validate({
		ignore: "",
		onsubmit: false,
        onfocusout : function( element, event ) {
		    if ($(element).valid()){
        		$(element).closest('div.admin_control_row').find('.category_group_warntip').removeClass("show");
		    	$(element).closest('div.admin_control_row').find('.category_group_warntip').addClass("hide");
		    }
		},
        onkeyup: function( element, event ) {
		    $(element).valid();
		},
		
        errorPlacement: function (error, element) {
            $(element).closest('div.admin_control_row').find('.category_group_warntip').removeClass("hide");
            $(element).closest('div.admin_control_row').find('.category_group_warntip').addClass("show");
            $(element).closest('div.admin_control_row').find(".warntip_content span").html(error.html());
        },
        invalidHandler: function(form, validator) {
            if (!validator.numberOfInvalids()){
                return;
            }
            scrollToTopElement($(validator.errorList[0].element));
        }
    });
    
}
function initRules(){
	$('#data_username').rules("add", {
            required : true,
            minlength: 2,
            messages: {
			    required: "Vui lòng nhập tên",
			    minlength: "Nhập ít nhất 2 ký tự"
			}
      });
    $('#data_email').rules("add", {
            required : true,
            email: true,
            messages: {
			    required: "Vui lòng nhập email",
			    email: "Email không hợp lệ"
			}
     });
}
function scrollToTopElement($element){
	//posting_element
    $('html, body').animate({
        scrollTop: $element.offset().top
    }, 100);
}


</script>